package sg.edu.nus.iss.phoenix.schedule.entity;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import sg.edu.nus.iss.phoenix.authenticate.entity.User;
import sg.edu.nus.iss.phoenix.radioprogram.entity.RadioProgram;

/**
 * Schedule Value Object. This class is value object representing database table
 * schedule. This class is intended to be used together with associated Dao object.
 * 
 * @author Low  Kheng Hian (A0092668N)
 * @author Nang Sai Hom (A0092617B)
 *  
 * @version 1.0 2012/9/27
 */


public class Schedule {
/** 
     * Persistent Instance variables. This data is directly 
     * mapped to the columns of database table.
     */
     
	private int scheduleId;
	private RadioProgram program;
	private Date startDate; 
	private Date endDate;
	private String startTime; 
	private String endTime;
	
   	/**
	 * This method is for formatting and parsing Schedule Slot start datetime.It allows 
	 * to start by choosing any user-defined patterns for date-time formatting 
	 * and return a date/time formatter initialized with a default format pattern.
	 */
    
	public String getStartTime() {
		SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String startTime = date_format.format(startDate);
		return startTime;
	}
   /**
	 * This method is allow to set start time of schedule slot and formatting date time. It allows 
	 * to start by choosing any user-defined patterns for date-time formatting 
	 * and return a date/time formatter initialized with a default format pattern.
	 */
    
	public void setStartTime(String startTime) {
		SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			// System.out.println(" scheule start time " + startTime);
			// System.out.println(" schedule start date  " + this.startDate);
			this.startDate = date_format.parse(startTime);
		
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
   /**
	 * This method is for formatting and parsing Schedule Slot end datetime.It allows 
	 * to start by choosing any user-defined patterns for date-time formatting 
	 * and return a date/time formatter initialized with a default format pattern.
	 */
	public String getEndTime() {
		SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		String endTime = date_format.format(endDate);
		return endTime;
	}
   /**
	 * This method is allow to set end time of schedule slot and formatting date time. It allows 
	 * to start by choosing any user-defined patterns for date-time formatting 
	 * and return a date/time formatter initialized with a default format pattern.
	 */
	
	public void setEndTime(String endTime) {
		SimpleDateFormat date_format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			this.endDate = date_format.parse(endTime);
		} catch (ParseException e) {
		    e.printStackTrace();
		}
	}
	private User presenter;
	private User producer;
   
    /* 
     * Get- and Set-methods for persistent variables. The default
     * behaviour does not make any checks against malformed data,
     * so these might require some manual additions.
     */
	/**
	 * This method is to get back the current schedule id.
	 * @return the current schedule id.
	 */
	public int getScheduleId() {
		return scheduleId;
	}
    /**
	 * This method allows the current schedule id to be set.
	 * @param scheduleId.
	 */
	public void setScheduleId(int scheduleId) {
		this.scheduleId = scheduleId;
	}
  
    	/**
	 * This method is to get back the current radio program.
	 * @return the current radio program.
	 */
	public RadioProgram getProgram() {
		return program;
	}
   	/**
	 * This method allows the current program to be set.
	 * @param radio program.
	 */	
	public void setProgram(RadioProgram program) {
		this.program = program;
	}
   	/**
	 * This method is to get back the current start date.
	 * @return the current start date.
	 */
    
	public Date getStartDate() {
		return startDate;
	}
   /**
	 * This method allows the current start date to be set.
	 * @param start date.
	 */	
    
	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}
   /**
	 * This method is to get back the current end date.
	 * @return the current end date.
	 */
	public Date getEndDate() {
		return endDate;
	}
   	/**
	 * This method allows the current end date to be set.
	 * @param end date.
	 */	
	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
   /**
	 * This method is to get back the current presenter.
	 * @return the current presenter.
	 */
	public User getPresenter() {
		return presenter;
	}
   	/**
	 * This method allows the current presenter to be set.
	 * @param presenter.
	 */	
	public void setPresenter(User presenter) {
		this.presenter = presenter;
	}
   	/**
	 * This method is to get back the current producer.
	 * @return the current producer.
	 */
	public User getProducer() {
		return producer;
	}
   	
	/**
	 * This method allows the current producer to be set.
	 * @param producer.
	 */	
	public void setProducer(User producer) {
		this.producer = producer;
	}
    /**
     * toString will return String object representing the state of this 
     * valueObject. This is useful during application development, and 
     * possibly when application is writing object states in text log.
     */
	
	@Override
	public String toString() {
		SimpleDateFormat date_format = new SimpleDateFormat("MMM dd,yyyy HH:mm");
		String endTime = date_format.format(endDate);
		String startTime = date_format.format(startDate);
		
		String s =  "Schedule [scheduleId=" + scheduleId + ", program=" + program
				+ ", startDate=" + startTime + ", endDate=" + endTime
				+ ", presenter=" + presenter + ", producer=" + producer + "]";
		
		return s;
	}
	
	
}
